using System.Linq;
using System.Text;

namespace WIT.Global;

/// <summary>
/// Byte/Byte[]扩展类
/// </summary>
public static class ByteExtension
{
	/// <summary>
	/// 将byte[]转换为16进制字符串
	/// </summary>
	/// <param name="bytes"></param>
	/// <returns></returns>
	public static string ToHexStr(this byte[] bytes)
	{
		return string.Join(" ", bytes.Select((byte t) => $"{t:X2}")).Trim();
	}

	/// <summary>
	/// 将byte[]转换为Encoding字符串
	/// </summary>
	/// <param name="bytes"></param>
	/// <returns></returns>
	public static string ToEncodingStr(this byte[] bytes)
	{
		return Encoding.Default.GetString(bytes).Trim();
	}
}
